package com.heyige.entity;

import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.time.LocalDateTime;

@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("ai_sessions")
public class AiSession {
    
    @TableId(type = IdType.AUTO)
    private Long id;
    
    @TableField("user_id")
    private Long userId;
    
    @TableField("title")
    private String title;
    
    @TableField("model_type")
    private String modelType = ModelType.CHATGPT.name();
    
    @TableField("message_count")
    private Integer messageCount = 0;
    
    @TableField("total_tokens")
    private Integer totalTokens = 0;
    
    @TableField("is_active")
    private Boolean isActive = true;
    
    @TableField(value = "last_message_time", fill = FieldFill.INSERT)
    private LocalDateTime lastMessageTime;
    
    @TableField(value = "created_at", fill = FieldFill.INSERT)
    private LocalDateTime createdAt;
    
    @TableField(value = "updated_at", fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime updatedAt;
    
    public enum ModelType {
        CHATGPT, DEEPSEEK, QWEN
    }
    
    /**
     * 增加消息计数
     */
    public void incrementMessageCount() {
        this.messageCount++;
        this.lastMessageTime = LocalDateTime.now();
    }
    
    /**
     * 增加token计数
     */
    public void addTokens(Integer tokens) {
        this.totalTokens += tokens;
    }
}